/*
 Copyright 2007, Lucid Technics, LLC.

 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
 except in compliance with the License. You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in
 writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 specific language governing permissions and limitations under the License.
*/

package dayzero;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;
import java.util.Iterator;

public class Simple {

    final Logger logger = LoggerFactory.getLogger(Simple.class);

    public int square(int x) {
        int result = x * x;
                                        
        logger.debug("The value of x is {} and the value x squared is {}", x, result);

        return result;
    }

    public int f(int x) {

        if (x < 0) {
            return square(x);
        } else if ((x >= 0) && (x <= 5)) {
            return x + 3;
        } else {
            return 2 * x;
        }
    }

    public int sum(Collection c) {
        int result = 0;

        for (Iterator i = c.iterator(); i.hasNext();) {
            int value = ((Number) i.next()).intValue();
            result += value;
        }

        return result;
    }
}